<template>
	<div style="height:100%">
		<cl-crud @load="onLoad">
			<template #table-column-isNewPerson="{scope}">
				<el-tag v-if="scope.row.isNewPerson == 1" type="success">是</el-tag>
				<el-tag type="info" v-else>否</el-tag>
			</template>
		</cl-crud>
	</div>
</template>

<script>
export default {
	data() {
		return {};
	},

	mounted() {},

	methods: {
		onLoad({ ctx, app }) {
			this.crud = app;
			ctx.service(this.$service.integralMall.bwbtGoldExchangeSetting)
				.set('table', {
					columns: [
						{
							prop: 'gold',
							label: '金币个数',
							align: 'center',
							sortable: 'custom'
						},
						{
							prop: 'amount',
							label: '兑换现金',
							align: 'center'
						},
						{
							prop: 'level',
							label: '排序',
							align: 'center'
						},
						{
							prop: 'isNewPerson',
							label: '是否新人',
							align: 'center'
						}
					],
					op: {
						layout: ['edit', 'delete']
					}
				})
				.set('upsert', {
					props: {
						labelWidth: '112px',
						with: '500px'
					},
					items: [
						{
							prop: 'gold',
							label: '金币个数',
							value: 1,
							component: {
								name: 'el-input-number',
								attrs: {
									min: 1
								},
								on: {
									change(val) {
										let num = val / 10000;
										app.setForm('amount', num);
									}
								}
							},

							rules: [
								{
									required: true,
									message: '请输入金币个数',
									trigger: 'blur'
								}
							]
						},
						{
							prop: 'amount',
							label: '兑换现金',
							value: 1,
							component: {
								name: 'el-input-number',
								attrs: {
									min: 0,
									precision: 2
								}
							},
							rules: [
								{
									required: true,
									message: '请输入兑换现金',
									trigger: 'blur'
								}
							]
						},
						{
							prop: 'level',
							label: '排序：',
							value: 1,
							component: {
								name: 'ysqlevels',
								data() {
									return {
										ysqLevel: 1
									};
								},
								props: {
									value: null
								},
								watch: {
									value(val) {
										this.ysqLevel = val;
									}
								},
								methods: {
									input(e) {
										this.$emit('input', e);
									}
								},
								render() {
									return (
										<div>
											<el-input-number
												v-model={this.ysqLevel}
												controls-position="right"
												onInput={this.input}
												min={1}
												max={10000}></el-input-number>
											<span style="color:#999999;margin-left:10px">
												序号越大，排序越靠前
											</span>
										</div>
									);
								}
							}
						},
						{
							prop: 'isNewPerson',
							label: '是否新人专享',
							value: 1,
							component: {
								name: 'el-radio-group',
								options: [
									{
										label: '是',
										value: 1
									},
									{
										label: '否',
										value: 0
									}
								]
							}
						}
					]
				})
				.set('layout', [
					['refresh-btn', 'add-btn'],
					['data-table'],
					['flex1', 'pagination']
				])
				.on('submit', async (isEdit, data, { next }) => {
					console.log(data);
					next({
						...data
					});
				})
				.done();
			app.refresh();
		}
	}
};
</script>
<style lang="scss" scoped></style>
